/**
 *  Copyright 2002-2009 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package foo.bar.blog.core.security.tags;

import foo.bar.blog.core.security.RoleType;
import org.jsecurity.web.tags.PermissionTag;

import java.util.Set;

/**
 * A tag that renders it's body content only when the current {@link org.jsecurity.subject.Subject}
 * has the jSecurity {@link foo.bar.blog.core.domain.Permission} defined by
 * {@link foo.bar.blog.core.security.RoleType}
 * <p/>
 * Eg.
 * <code>
 * <sample:hasRoleTypePermission name="ALL">
 *   ...
 * </sample:hasRoleTypePermission>
 * </code>
 * <p/>
 * The content will be rendered if the current {@link org.jsecurity.subject.Subject}
 * has jSecurity's {@link org.jsecurity.authz.Permission} identified by
 * {@link foo.bar.blog.core.security.RoleType#ADMINISTRATOR}
 *
 * @author tmjee
 * @version $Date: 2009-06-27 15:56:30 +0000 (Sat, 27 Jun 2009) $ $Id$
 */
public class HasRoleTypePermissionTag extends PermissionTag {

    protected boolean showTagBody(String p) {
        RoleType roleType = RoleType.valueOf(p);
        Set perms = roleType.permission();
        return getSubject().isPermittedAll((String[])perms.toArray(new String[0]));
    }


}
